package com.youyi.flymewallpager.dialog;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.NumberPicker;

import com.youyi.flymewallpager.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by xzp on 16/7/8.
 */
public class NumberDialog extends BaseDialog{
    private OnNumberListener mNumberListener;
    @BindView(R.id.number_picker)
    NumberPicker mPick;
    public void setNumberListener(OnNumberListener listener) {
        this.mNumberListener = listener;
    }

    @Override
    int getLayoutRes() {
        return R.layout.dialog_number;
    }

    @Override
    void init(Bundle savedInstanceState) {
        mPick.setMinValue(1);
        mPick.setMaxValue(10);
    }

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder=new AlertDialog.Builder(getContext());
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if(mNumberListener!=null) {
                    mNumberListener.onNumber(mPick.getValue());
                }
            }
        });
        return builder.create();
    }

    public interface OnNumberListener{
        void onNumber(int number);
    }
}
